package org.teamh.gui.loadingscreen;

import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glLoadIdentity;

import org.teamh.gui.Event;
import org.teamh.gui.GUI;
import org.teamh.gui.Screen;

import de.lessvoid.nifty.builder.EffectBuilder;
import de.lessvoid.nifty.builder.ImageBuilder;
import de.lessvoid.nifty.builder.LayerBuilder;
import de.lessvoid.nifty.builder.PanelBuilder;
import de.lessvoid.nifty.builder.ScreenBuilder;
import de.lessvoid.nifty.builder.TextBuilder;
import de.lessvoid.nifty.tools.Color;

public class LoadingScreen implements Screen{

	private GUI gui;
	
	private de.lessvoid.nifty.screen.Screen screen;

	public LoadingScreen(GUI gui) {
		this.gui = gui;
	}
	
	@Override
	public void build() {
		     
			screen = new ScreenBuilder("loadingScreen") {{

			controller(new LoadingScreenController(gui));
			layer(new LayerBuilder() {{
				childLayoutVertical();	
				    paddingTop("150");
					backgroundColor(new Color(0.4f, 0.4f, 0.4f, 1));
					height("100%");
					width("100%");
				
					
					
				
					
					
					
				//Panel um LoadingGif,Logo etc
				panel(new PanelBuilder(){{
				 paddingTop("60");
				 childLayoutVertical();
				 height("350");
				 width("500");
				 backgroundColor(new Color(0,0,0,0.1f));
				 alignCenter();
				 valignCenter();
				 
				 //Logo etc
				 
				 panel(new PanelBuilder() {{
						childLayoutHorizontal();
						paddingLeft("100");
						panel(new PanelBuilder() {{ // logo und so
							childLayoutCenter();
							height("120");
							width("100");
							image(new ImageBuilder("logo") {{
								height("96");
								width("76");
								filename("res/img/logo/wasp_edited.png");								
							}});
						}});
						panel(new PanelBuilder() {{
							childLayoutVertical();
							width("180");
							panel(new PanelBuilder() {{
								height("20");
							}});
							panel(new PanelBuilder() {{
								childLayoutCenter();
								color(new Color(1,1,0,1));
								width("180");
								text(new TextBuilder() {{
									font("verdana-small-regular.fnt");
									color(new Color(1,1,1,1));
									text("Wasp Enterprises");
								}});
							}});
							
							panel(new PanelBuilder() {{
								childLayoutCenter();
								color(new Color(1,0,1,1));
								width("172");

								text(new TextBuilder() {{
									font("res/font/aurulent-sans-36.fnt");
									color(new Color(1,1,1,1));
									text("CreepSmash");
								}});
							}});
							
						}});
					}});
				 
				 
				 
				 //ENDE Logo etc
				 //LoadingText
					panel(new PanelBuilder() {{ 
						childLayoutCenter();
						//paddingLeft("50");
						//paddingLeft("20");
						paddingTop("80");
						paddingLeft("180");
						height("50");
						text(new TextBuilder() {{
							font("verdana-small-regular.fnt");
							color(new Color(1,1,1,1));
							text("LOADING DATA..");
							onActiveEffect(new EffectBuilder("colorPulsate") {{
			    		        effectParameter("period", "1600");
			    		        effectParameter("startColor", "#00000000");
			    		        effectParameter("endColor", "#ffffffff");
			    				}});	
						}});
						visible(true);
					}});
				 //ENDE LoadingText
				 
//				 //LoadingGif
//				 panel(new PanelBuilder(){{//BILD
//					 childLayoutVertical();
//					 height("400px");
//					 width("200px");
//					 alignCenter();
//					 valignCenter();
//					 image(new ImageBuilder(){{
//		                 	filename("res/img/loadingScreen/loadingscreen.gif");
//		                 	height("43px");
//		                 	width("482px");
//		                 	alignCenter();
//		    				valignCenter();
//		    				visible(true);
//							}}
//							);
//					}});//ENDE LoadingGif
//				 //Image img = Toolkit.getDefaultToolkit().getImage("bild.gif");
//				 //g2D.drawImage(img);

				}});//ENDE LoadingGif
				 		
				
				
				
			}});//ENDE Panel um LoadingGif,Logo etc
		}}.build(gui.getNifty());
		
		gui.getNifty().addScreen("loadingScreen", screen);
		
	}

	@Override
	public void render(float timeElapsed) {
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glLoadIdentity();
		
		
	}

	@Override
	public void init() {}

	@Override
	public void keyPressed(int key) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyReleased(int key) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(int posX, int posY, int button) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(int posX, int posY, int button) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseMoved(int posX, int posY, int button) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseDragged(int posX, int posY, int button) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseWheelMoved(int movement) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dealloc() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void eventOccured(Event event) {
		// TODO Auto-generated method stub
		
	}
	
	public boolean canPoll() {
		return false;
	}

	@Override
	public String getNiftyScreenID() {
		return "loadingScreen";
	}
}

